我试图编写一个php脚本,它将为Textarea帖子中的每一行循环一个进程.我想知道是否有人可以发布一个例子.
考虑以下代码:
var x = 0;
do {
$.ajax({
type: "POST",
url: someurl,
dataType: 'xml',
data: xmlString,
success: function(xml) {
x++;
}
} while(x<10);
Run Code Online (Sandbox Code Playgroud)
当然,这不起作用,因为将向“someurl”发出数千个请求,那么我将如何更改此代码以使条件do while取决于异步 HTTP 请求的回调?换句话说,如何让 do-while 循环仅在调用请求回调时继续?因此只会进行 11 次迭代,而不是数千次。
我有一个while循环,应该读取数组的元素来尝试找到给定的值variable,但是,循环执行自己无限次,我不明白为什么.它应该在找到它正在寻找的值后退出; 我知道它确实找到它正在寻找的东西,因为它打印出I've found it!无限次.该方法的代码到目前为止是:
try{
System.out.println("Enter your card number to access your account:");
int CardNumber = sc.nextInt();
String CardNumberStr = Integer.toString(CardNumber);
boolean Exist = false;
String LineNo;
String [] CardNum = {};
int Counter;
FileReader fileReader = new FileReader("VirtualATM.txt");
BufferedReader bufferedReader = new BufferedReader(fileReader);
line = bufferedReader.readLine();
CardNum = line.split("\\s+");
do{
for(Counter = 0; Counter < CardNum.length; Counter++){
LineNo = CardNum[Counter];
if(LineNo.contains(CardNumberStr)){
Exist = true;
System.out.println("I've found it!");
}
else if(Counter == CardNum.length){
Exist=false;
}
} …Run Code Online (Sandbox Code Playgroud) 我是一名新的java程序员,我正在编写一个程序,为3台打印机设置3个型号.如果用户输入了错误的值,我希望它继续向用户询问型号.我得到了它的工作,但只有当用户的第一个值在3个打印机之一的数字之间.如果第一个值不是可能值之一而第二个输入是,它仍然会重复循环.
package printing;
import java.util.Scanner;
public class newClass {
public static void main(String[] args) {
int count = 0;
String machine1 = "546";
String machine2 = "892";
String machine3 = "127";
Scanner s = new Scanner(System.in);
System.out.print("Model Number:");
String modelNumber = s.nextLine();
// increment count if first input value is wrong
if (!s.equals(machine1) || !s.equals(machine2) || !s.equals(machine3))
count++;
// if user inputs right value
while (true) {
if (modelNumber.equals(machine1)) {
System.out.println("Machine 1 is online");
break;
}
if (modelNumber.equals(machine2)) {
System.out.println("Machine …Run Code Online (Sandbox Code Playgroud) 我不明白嵌套的do-while循环如何丢弃其他字符,为什么会有换行语法.有人可以解释一下,非常感谢.
public class guessGame {
public static void main(String[] args) throws java.io.IOException{
char ch, ignore,answer='K';
do {
System.out.println("I'm thinking of a letter between A and Z.");
System.out.print("Can you guess it:");
//read a character
ch=(char) System.in.read();
// ************ here ************
do {
ignore =(char) System.in.read();
} while (ignore != '\n');
// ************ to here ************
if (ch==answer) System.out.println("** Right **");
else {
System.out.print("...Sorry, you're ");
if(ch<answer) System.out.println("too low");
else System.out.println("Too high");
System.out.println("Try again\n");
}
} while (answer !=ch);
}
}
Run Code Online (Sandbox Code Playgroud) 第一个循环是完美的。第二不起作用。“ Z”怎么了?为什么循环不停止?当我在表中输入“ Z”时,循环不响应。
#include <iostream>
using namespace std;
int main()
{
char tab[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G',
'H', 'I', 'J', 'K', 'L', 'M', 'N',
'O', 'P', 'Q', 'R', 'S', 'T', 'U',
'V', 'W', 'X', 'Y', 'Z' };
char *wsk = tab;
while(*wsk <= 'Y')
{
cout << *wsk << " ";
wsk++;
}
cout << endl;
wsk = tab;
while(*wsk <= 'Z')
{
cout << *wsk << " ";
wsk++;
}
cout << endl;
}
Run Code Online (Sandbox Code Playgroud) import java.util.*;
import java.lang.*;
import java.io.*;
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
int i = 0;
do while ( i < 10 )
System.out.print("The value of i is " + i);
while ( i > 10 ) ;
}
}
Run Code Online (Sandbox Code Playgroud)
为什么这段代码没有抛出语法错误?while后面没有分号。
考虑到and循环中的公共while()语句,do ... while以及while循环while体被 a 上的分号替换的位置的方式,就do ... while好像它是一个复合语句被变成一个空语句(或结束一个长语句的行):
任何 C 家族语言中的语法是否都允许“do while 和 while”循环同时定义两个主体?
据推测,语义将是一个循环,其中一些操作在检查之前发生,一些在之后发生。
例如:
do {
foo();
} while ( baz() == true ){
bar();
}
Run Code Online (Sandbox Code Playgroud)
foo()总是会发生一次,但bar()只有在baz()返回 true后才会发生。
我想使用JAVA生成一个随机日期( date2),它应该大于当前日期( )date1
为了实现这一目标,我尝试遵循 do-while 循环,但它无法正常运行。
我怎样才能让它发挥作用?或者有更好的方法来获得想要的结果吗?
PS JAVA 不太好,所以非常感谢您的支持!
public static void main(String[] args) throws ParseException {
do {
Calendar c = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date date1 = sdf.parse(""+String.valueOf(c.get(Calendar.YEAR))+"-"+String.valueOf(c.get(Calendar.DAY_OF_MONTH))+"-"+String.valueOf(c.get(Calendar.DATE))+"");
Date date2 = sdf.parse(""+String.valueOf(c.get(Calendar.YEAR))+"-"+createRandomIntBetween(1, 12)+"-"+createRandomIntBetween(1, 28)+"");
}
while (date1.compareTo(date2) < 0);
}
public static int createRandomIntBetween(int start, int end) {
return start + (int) Math.round(Math.random() * (end - start));
}
Run Code Online (Sandbox Code Playgroud) 如何仅使用 goto 语句实现do-while循环?
do{
// Some code
}
while ();
Run Code Online (Sandbox Code Playgroud)
像这样,但仅使用 goto 来创建与之等效的内容。