使用if语句的条件循环(Conditional loop using if statement)
我正在学习一些基本的javascript,并希望学习如何在满足某些条件时返回到方法的开头。
在这种情况下,用户必须在提示中输入一个字符才能继续执行“您输入的字符是”字符串的语句。 我想实现一个循环,如果没有输入任何内容,则将程序发送回方法的开头。 到目前为止,我有以下内容:
<script class="promptwindow"> var x x = prompt("Please type a character in the box and click OK", "") if (x = null) {****} document.write("The character you typed was ", x) </script>
我不确定在****括号中使用什么,我需要类似于
goto
东西。编辑:是的,应该是
==
。 我会把错误留在那里,以便评论有意义。I'm learning some basic javascript, and would like to learn how to return to the beginning of a method when certain conditions are met.
In this scenario, the user must enter a character in the prompt in order to proceed to the statment "The character you typed was" string. I would like to implement a loop to send the program back to the start of the method if nothing is entered. I have the following, so far:
<script class="promptwindow"> var x x = prompt("Please type a character in the box and click OK", "") if (x = null) {****} document.write("The character you typed was ", x) </script>
I'm unsure what to use in the **** bracket, I need something similar to
goto
.Edit: Yep, should have been
==
. I'll leave the mistake there so that the comments make sense.
原文:https://stackoverflow.com/questions/25526879
最满意答案
不,你的假设是错的。 是不可能的。
使用归纳证明相当容易,当完成顶点“a”的处理时,已经发现了从“a”(例如“b”)可到达的所有顶点。
No, your assumption is wrong. It is impossible.
It is fairly easy to prove using induction that when processing of vertex "a" is done, all vertices reachable from "a" (e.g. "b") has already been discovered.
相关问答
更多-
深度优先搜索邻接(Depth First Search Adjacency)[2022-02-09]
没有放弃太多,我会解释这个。 你可以像这样迭代dict的键: for k in mydict: ... 在你的例子中: for neighbor in G[node]: # Assumes your defaultdict is `G`. ... 由于键是相邻节点,因此您可以对它们进行操作。 Without giving away too much, I'll explain this. You can iterate through the keys of a dict like th ... -
虽然已经发布(并接受)答案,但我认为昨天晚上发布我在这个问题上工作没有任何损害。 我从新手的角度来看更多的这个问题,而不是使用现有的图/树遍历算法。 我的第一个尝试是从上而下的级别渲染。 在这个更简单的尝试中,我基本上把所有的人都按层次排列,并从上而下渲染。 这也是我的第一个尝试。 您可以从上而下或从自下而上或从根开始遍历树。 由于您受到特定网站的启发,从根本开始似乎是一个合乎逻辑的选择。 但是,我发现自下而上的方法更简单易懂。 这是一个粗暴的尝试: 绘制数据: 我们从最底层开始,向上工作。 正如您正在尝试 ...
-
深度优先搜索边缘属性(Depth-first search by edge property)[2022-04-14]
您应该首先创建一个过滤图。 你可以做: u = GraphView(g, efilt=rel_need) 其中rel_need是一个布尔属性映射,其中rel_need[e] == True表示边缘未被滤除。 然后,您可以继续使用图形u进行DFS搜索,并忽略rel_need[e] == False的边缘。 You should create a filtered graph first. You can do: u = GraphView(g, efilt=rel_need) where rel_need ... -
深度优先搜索主要用于查找图中两个节点之间的路径。 您的示例图表已断开连接 ,即图表中存在两个节点,因此图表中没有路径将这些节点作为端点。 6和8显然是属于不同子图的节点,因此您找不到0到8之间的路径,并且DFS将返回IMPOSSIBLE或No path found 。 除此之外你的图表是正确的。 Depth first search is basically used to find a path between two nodes in a graph. The graph of your example ...
-
您的数据结构确实是一个图表。 我讨厌提供这样一个简单的答案,但问题是如此基本,维基百科上的Graph Traversal绰绰有余 。 解释了两种基本方法,并且还存在伪代码。 Your data structure is indeed a graph. I hate to provide such a bare answer, but the question is so basic that Graph Traversal on Wikipedia is more than adequate. The tw ...
-
创建一个继承自抽象Sutsama DFS的类,然后您可以创建此类的实例并使用它来调用void Run(IGraph graph,IEnumerable roots = null)方法进行搜索。 (可选)您可以覆盖抽象类的虚方法以自定义搜索算法。 Create a class which inherits from abstract Sutsama DFS and then you can create an instance of this class and call void Run (IGraph g ...
-
考虑可能的4种情况(理论上)。 边缘可以是: 树边缘 后缘 树边缘和后边缘 无论是树边还是背边 为了证明需要什么,你需要证明案例3和4不会发生,即导致矛盾。 Consider the 4 cases possible (theoretically). An edge can be: A tree edge A back edge Both a tree edge and a back edge Neither a tree edge or a back edge To prove what is neede ...
-
深度优先搜索基础知识(Depth First Search Basics)[2022-12-01]
通常,是的,深度优先搜索的想法是您不必生成(或“访问”或“扩展”)每个节点。 在八皇后问题的情况下,如果你放置一个女王,它可以攻击另一个女王,你可以中止该分支; 它不能导致解决方案。 如果您正在解决八皇后的变体,那么您的目标是找到一个解决方案,而不是全部92 个解决方案,那么您可以在找到解决方案后立即退出。 更一般地说,如果你正在解决一个不那么离散的问题,比如根据某种方法找到皇后的“最佳”安排,那么一旦你知道它不能导致最终状态比最终状态更好,你就可以中止一个分支。你已经在另一个分支上找到了。 这与A *搜索 ... -
序言图深度优先搜索(prolog graph depth first search)[2023-04-20]
传统的DFS算法涉及递归和基本上是回溯机制的堆栈。 在Prolog中,如果你试图“积累”一个列表,如果你需要的元素是在回溯时获得的话,这可能会很有挑战性。 以下代码是DFS搜索的非常简单的渲染,并将在DFS搜索中写出节点: dfs(Graph, StartNode) :- dfs(Graph, StartNode, []). dfs(Graph, Node, Visited) :- \+ member(Node, Visited), member(Node-Neighbors, G ... -
不,你的假设是错的。 是不可能的。 使用归纳证明相当容易,当完成顶点“a”的处理时,已经发现了从“a”(例如“b”)可到达的所有顶点。 No, your assumption is wrong. It is impossible. It is fairly easy to prove using induction that when processing of vertex "a" is done, all vertices reachable from "a" (e.g. "b") has alread ...