for循环没有停止它应该 [英] for loop not stopping when it should

查看:91
本文介绍了for循环没有停止它应该的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在检查并查看是否输入了数字以外的其他内容(+,

- ,*或/)一个文本框,其中bigR就是我所说的文本框中的文本。我可以得到输入的内容和字符串中的位置(

,其中部分是下面的第一部分)。我遇到麻烦只是

之后。我测试了breakpt [0]的值是多少,得到3,如果输入100 + 200那么它应该是
。但是当我运行j = 0到j
$时b $ b =< breakpt [0],它不会停在2,但一直持续到索引结束

数组。

如果消息框说breakpt [0] = 3,为什么不止于2?

谢谢!!!

Melanie


int i,j;

for(i = 0; i< bigR.Length; i ++)

{

if((bigR [i] ==' '+'')||(bigR [i] =='' - '')||(bigR [i] ==''*'')||(bigR [i]

==''/''))

{breakpt + = i;}

}


// breakpt [0 ] = 3如果类型100 + 200


MessageBox.Show(breakpt [0] .ToString());

for(j = 0; j< ; breakpt [0]; j ++)

{

MessageBox.Show(j.ToString());

nums + = bigR [j ];

}

Hi,
I''m trying to check and see if something other than numbers (either the +,
-, *, or /) are entered into a textbox, where bigR is what I call the text in
the textbox. I can get what was entered and where along the string (the
where part is the first section of below). I''m running into trouble just
after that. I tested what the value of breakpt[0] and got 3, which it should
be if entering something like 100 + 200. But when I run the for j = 0 to j
= < breakpt[0], it doesn''t stop at 2, but keeps going until the index is out
of the array.
If the messagebox says breakpt[0] = 3, why doesn''t j stop at 2?
Thanks!!!
Melanie

int i, j;
for(i = 0; i < bigR.Length; i++)
{
if ((bigR[i] == ''+'') || (bigR[i] == ''-'') || (bigR[i] == ''*'') || (bigR[i]
== ''/''))
{breakpt += i;}
}

// breakpt[0] = 3 if type 100+200

MessageBox.Show(breakpt[0].ToString());
for (j = 0; j < breakpt[0]; j++)
{
MessageBox.Show(j.ToString());
nums += bigR[j];
}

推荐答案

melanieab写道:
melanieab wrote:
<我正在尝试检查并查看数字以外的其他内容(
+, - ,*或/)是否输入到文本框中,wh bigR是我在文本框中调用文本的内容。我可以得到输入的内容和字符串中的
(其中部分是下面的第一部分)。我刚刚在那之后遇到了麻烦。我测试了
breakpt [0]的值是什么,得到3,如果输入类似
100 + 200的话应该是。但是当我运行for j = 0到j =< breakpt [0],它不会停在2,但一直持续到索引超出
数组。
如果消息框说breakpt [0] = 3,为什么难道不止于2点吗?
谢谢!!!


对于(i = 0;我< bigR.Length)我是,j;
; i ++)
{
if((bigR [i] ==''+'')||(bigR [i] =='' - '')||(bigR [i] = =''*'')||
(bigR [i] ==''/''))
{breakpt + = i;}
}
// breakpt [0] = 3 if type 100 + 200
MessageBox.Show(breakpt [0] .ToString());
for(j = 0; j< breakpt [0]; j ++)
{MessageBox.Show(j.ToString());
nums + = bigR [j];
}
Hi,
I''m trying to check and see if something other than numbers (either
the +, -, *, or /) are entered into a textbox, where bigR is what I
call the text in the textbox. I can get what was entered and where
along the string (the where part is the first section of below). I''m
running into trouble just after that. I tested what the value of
breakpt[0] and got 3, which it should be if entering something like
100 + 200. But when I run the for j = 0 to j = < breakpt[0], it
doesn''t stop at 2, but keeps going until the index is out of the
array.
If the messagebox says breakpt[0] = 3, why doesn''t j stop at 2?
Thanks!!!
Melanie

int i, j;
for(i = 0; i < bigR.Length; i++)
{
if ((bigR[i] == ''+'') || (bigR[i] == ''-'') || (bigR[i] == ''*'') ||
(bigR[i] == ''/''))
{breakpt += i;}
}

// breakpt[0] = 3 if type 100+200

MessageBox.Show(breakpt[0].ToString());
for (j = 0; j < breakpt[0]; j++)
{
MessageBox.Show(j.ToString());
nums += bigR[j];
}




breakpt的类型是什么?

首先使用breakpt + = i;; (没有[],看起来像整数加法)

然后你使用breakpt [0];所以它不能是一个整数。


如果在j之前会发生什么?循环,你做

int max = breakpt [0];

然后结束循环j< MAX" ?

Hans Kesting



What is the type of "breakpt"?
First you use "breakpt += i;" (no [], looks like integer addition)
Then you use "breakpt[0];" so it can''t be an integer.

What happens if just before the "j" loop, you do
int max = breakpt[0];
and then end the loop on "j < max" ?
Hans Kesting


嗨再次,

breakpt是我在程序中先前定义的字符串(字符串) breakpt =

"";)。

当我说breakpt + = i时,我得到一串数字告诉我哪里有+,

- ,*或/已输入。 (如果我输入100 + 200/20,breakpt将是37)。

然后当我使用breakpt [0]时,它会给我字符串中的第一个字符。

我尝试了你建议的int max,但得到了和以前一样的东西 -

第二个消息框显示j从0开始直到崩溃时它是

数组。

我也试过说

for(j = 0; j< int.Parse(breakpt [0]); j ++ )

并得到一个错误('int.Parse(字符串)的最佳重载方法匹配''

有一些无效的参数)。

帮助!任何想法???

谢谢!

Melanie


" Hans Kesting"写道:
Hi again,
breakpt is a string that I define earlier in the program (string breakpt =
"";).
When I say breakpt += i, I get a string of numbers that tell me where a +,
-, *, or / was entered. (if I entered 100+200/20 , breakpt would be "37").
Then when I use breakpt[0], it gives me the first character in the string.
I tried the int max thing you suggested, but get the same thing as before -
the second messagebox shows j going from 0 on up until it crashes when it''s
out of the array.
I also tried saying
for (j = 0; j < int.Parse(breakpt[0]); j++)
and got an error (The best overloaded method match for ''int.Parse(string)''
has some invalid arguments).
Help! Any ideas???
Thanks!
Melanie

"Hans Kesting" wrote:
melanieab写道:
melanieab wrote:

我正在检查并查看数字以外的其他内容(
+, - ,*或/)被输入到文本框中,其中bigR是我在文本框中调用文本的内容。我可以得到输入的内容和字符串中的
(其中部分是下面的第一部分)。我刚刚在那之后遇到了麻烦。我测试了
breakpt [0]的值是什么,得到3,如果输入类似
100 + 200的话应该是。但是当我运行for j = 0到j =< breakpt [0],它不会停在2,但一直持续到索引超出
数组。
如果消息框说breakpt [0] = 3,为什么难道不止于2点吗?
谢谢!!!


对于(i = 0;我< bigR.Length)我是,j;
; i ++)
{
if((bigR [i] ==''+'')||(bigR [i] =='' - '')||(bigR [i] = =''*'')||
(bigR [i] ==''/''))
{breakpt + = i;}
}
// breakpt [0] = 3 if type 100 + 200
MessageBox.Show(breakpt [0] .ToString());
for(j = 0; j< breakpt [0]; j ++)
{MessageBox.Show(j.ToString());
nums + = bigR [j];
}
Hi,
I''m trying to check and see if something other than numbers (either
the +, -, *, or /) are entered into a textbox, where bigR is what I
call the text in the textbox. I can get what was entered and where
along the string (the where part is the first section of below). I''m
running into trouble just after that. I tested what the value of
breakpt[0] and got 3, which it should be if entering something like
100 + 200. But when I run the for j = 0 to j = < breakpt[0], it
doesn''t stop at 2, but keeps going until the index is out of the
array.
If the messagebox says breakpt[0] = 3, why doesn''t j stop at 2?
Thanks!!!
Melanie

int i, j;
for(i = 0; i < bigR.Length; i++)
{
if ((bigR[i] == ''+'') || (bigR[i] == ''-'') || (bigR[i] == ''*'') ||
(bigR[i] == ''/''))
{breakpt += i;}
}

// breakpt[0] = 3 if type 100+200

MessageBox.Show(breakpt[0].ToString());
for (j = 0; j < breakpt[0]; j++)
{
MessageBox.Show(j.ToString());
nums += bigR[j];
}



breakpt的类型是什么?
首先使用breakpt + = i; (没有[],看起来像整数加法)
然后你使用breakpt [0];所以它不能是一个整数。

如果在j之前会发生什么?循环,你做
int max = breakpt [0];
然后结束循环j< MAX" ?

Hans Kesting



What is the type of "breakpt"?
First you use "breakpt += i;" (no [], looks like integer addition)
Then you use "breakpt[0];" so it can''t be an integer.

What happens if just before the "j" loop, you do
int max = breakpt[0];
and then end the loop on "j < max" ?
Hans Kesting



我也试过

int k =(int )(breakpt [0])

看起来应该可以工作(将字符转换为整数),但是不是。


" melanieab"写道:
I also tried
int k = (int)(breakpt[0])
which seems like it should work (converts characters to ints), but isn''t .

"melanieab" wrote:
嗨再次,
breakpt是我在程序前面定义的一个字符串(string breakpt =
"";)。
当我说breakpt + = i时,我得到一串数字,告诉我输入了+,
- ,*或/的位置。 (如果我输入100 + 200/20,breakpt将是37)。
然后当我使用breakpt [0]时,它会给我字符串中的第一个字符。
我尝试了int你建议的最大的东西,但得到与以前相同的东西 -
第二个消息框显示j从0开始直到它崩溃时,它是从阵列中出来的。
我也是尝试说
for(j = 0; j< int.Parse(breakpt [0]); j ++)
并得到一个错误(最好的重载方法匹配''int.Parse(string) ''
有一些无效的论点。)
帮助!任何想法???
谢谢!
Melanie

Hans Kesting写道:
Hi again,
breakpt is a string that I define earlier in the program (string breakpt =
"";).
When I say breakpt += i, I get a string of numbers that tell me where a +,
-, *, or / was entered. (if I entered 100+200/20 , breakpt would be "37").
Then when I use breakpt[0], it gives me the first character in the string.
I tried the int max thing you suggested, but get the same thing as before -
the second messagebox shows j going from 0 on up until it crashes when it''s
out of the array.
I also tried saying
for (j = 0; j < int.Parse(breakpt[0]); j++)
and got an error (The best overloaded method match for ''int.Parse(string)''
has some invalid arguments).
Help! Any ideas???
Thanks!
Melanie

"Hans Kesting" wrote:
melanieab写道:
melanieab wrote:

我正在检查并查看数字以外的其他内容(
+, - ,*或/)被输入到文本框中,其中bigR是我在文本框中调用文本的内容。我可以得到输入的内容和字符串中的
(其中部分是下面的第一部分)。我刚刚在那之后遇到了麻烦。我测试了
breakpt [0]的值是什么,得到3,如果输入类似
100 + 200的话应该是。但是当我运行for j = 0到j =< breakpt [0],它不会停在2,但一直持续到索引超出
数组。
如果消息框说breakpt [0] = 3,为什么难道不止于2点吗?
谢谢!!!


对于(i = 0;我< bigR.Length)我是,j;
; i ++)
{
if((bigR [i] ==''+'')||(bigR [i] =='' - '')||(bigR [i] = =''*'')||
(bigR [i] ==''/''))
{breakpt + = i;}
}
// breakpt [0] = 3 if type 100 + 200
MessageBox.Show(breakpt [0] .ToString());
for(j = 0; j< breakpt [0]; j ++)
{MessageBox.Show(j.ToString());
nums + = bigR [j];
}
Hi,
I''m trying to check and see if something other than numbers (either
the +, -, *, or /) are entered into a textbox, where bigR is what I
call the text in the textbox. I can get what was entered and where
along the string (the where part is the first section of below). I''m
running into trouble just after that. I tested what the value of
breakpt[0] and got 3, which it should be if entering something like
100 + 200. But when I run the for j = 0 to j = < breakpt[0], it
doesn''t stop at 2, but keeps going until the index is out of the
array.
If the messagebox says breakpt[0] = 3, why doesn''t j stop at 2?
Thanks!!!
Melanie

int i, j;
for(i = 0; i < bigR.Length; i++)
{
if ((bigR[i] == ''+'') || (bigR[i] == ''-'') || (bigR[i] == ''*'') ||
(bigR[i] == ''/''))
{breakpt += i;}
}

// breakpt[0] = 3 if type 100+200

MessageBox.Show(breakpt[0].ToString());
for (j = 0; j < breakpt[0]; j++)
{
MessageBox.Show(j.ToString());
nums += bigR[j];
}



breakpt的类型是什么?
首先使用breakpt + = i; (没有[],看起来像整数加法)
然后你使用breakpt [0];所以它不能是一个整数。

如果在j之前会发生什么?循环,你做
int max = breakpt [0];
然后结束循环j< MAX" ?

Hans Kesting



What is the type of "breakpt"?
First you use "breakpt += i;" (no [], looks like integer addition)
Then you use "breakpt[0];" so it can''t be an integer.

What happens if just before the "j" loop, you do
int max = breakpt[0];
and then end the loop on "j < max" ?
Hans Kesting



这篇关于for循环没有停止它应该的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆