首页 \ 问答 \ 使用if语句的条件循环(Conditional loop using if statement)

使用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
更新时间:2023-07-04 19:07

最满意答案

不,你的假设是错的。 是不可能的。

使用归纳证明相当容易,当完成顶点“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.

相关问答

更多
  • 没有放弃太多,我会解释这个。 你可以像这样迭代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 ...
  • 虽然已经发布(并接受)答案,但我认为昨天晚上发布我在这个问题上工作没有任何损害。 我从新手的角度来看更多的这个问题,而不是使用现有的图/树遍历算法。 我的第一个尝试是从上而下的级别渲染。 在这个更简单的尝试中,我基本上把所有的人都按层次排列,并从上而下渲染。 这也是我的第一个尝试。 您可以从上而下或从自下而上或从根开始遍历树。 由于您受到特定网站的启发,从根本开始似乎是一个合乎逻辑的选择。 但是,我发现自下而上的方法更简单易懂。 这是一个粗暴的尝试: 绘制数据: 我们从最底层开始,向上工作。 正如您正在尝试 ...
  • 您应该首先创建一个过滤图。 你可以做: 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 ...
  • 通常,是的,深度优先搜索的想法是您不必生成(或“访问”或“扩展”)每个节点。 在八皇后问题的情况下,如果你放置一个女王,它可以攻击另一个女王,你可以中止该分支; 它不能导致解决方案。 如果您正在解决八皇后的变体,那么您的目标是找到一个解决方案,而不是全部92 个解决方案,那么您可以在找到解决方案后立即退出。 更一般地说,如果你正在解决一个不那么离散的问题,比如根据某种方法找到皇后的“最佳”安排,那么一旦你知道它不能导致最终状态比最终状态更好,你就可以中止一个分支。你已经在另一个分支上找到了。 这与A *搜索 ...
  • 传统的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 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。