Results 1 to 8 of 8
Thread: problem with loop
- 12-31-2011, 01:17 PM #1
Member
- Join Date
- Dec 2011
- Posts
- 6
- Rep Power
- 0
- 12-31-2011, 01:23 PM #2
Re: problem with loop
You have an array named: a that can hold some values (don't know how many because you do not show the size of the array).I would like to change all my variables "a"
Where are the variables: a1,a2, etc How are those variables related to the array?
What do you mean by 'change all my variables "a"'?
-
- 12-31-2011, 04:14 PM #4
Member
- Join Date
- Dec 2011
- Posts
- 6
- Rep Power
- 0
Re: problem with loop
There is no array.
I just want to change values of those int variables (named: a1, ..., a5) at the same time.
I do not want to change their values individually. Perhaps in some place in my program I need to "reset" value of every variable (a5=10 and I need a5=0...).
I wonder if there is possibility to "reset" their values using a loop instead of write individually a1=0; a2=0; ... ; a5=0 (and in some extreme cases a10000=0;) ??
I'm just curious...Last edited by pietr0; 12-31-2011 at 04:21 PM.
- 12-31-2011, 04:21 PM #5
Re: problem with loop
This will change all those variables in one statement:I just want to change values of those int variables (named: a1, ..., a5) at the same time.
a0=a1=a2=a3=a4=a5=0;
- 12-31-2011, 04:24 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,413
- Blog Entries
- 7
- Rep Power
- 17
Re: problem with loop
It seems as if you are afraid of arrays; an array 'a' is like a block of houses with house numbers 0, 1, 2, 3 etc. so a[0] is a house, a[1] is a house, etc. and each house serves as a single variable. You can set each variable to, say, 42, like this:
You can't use a loop with individual variables a0, a1, a2 etc. in JavaJava Code:for (int i= 0; i < a.length; i++) a[i]= 42;
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
-
Re: problem with loop
Add the items to an array like this:
int[] a = new int[] { a1, a2, a3, a4, a5 };
So you'll be able to loop through the values with
a[i] = ...
where 0 <= i <= 4Last edited by ozzyman; 12-31-2011 at 05:07 PM.
- 12-31-2011, 04:58 PM #8
Similar Threads
-
Problem with while loop, assigning a variable with a different value every loop? Help
By JavaProg in forum New To JavaReplies: 2Last Post: 11-07-2011, 02:25 AM -
simple line problem / for loop problem
By helpisontheway in forum New To JavaReplies: 1Last Post: 11-17-2009, 06:12 AM -
Problem with loop
By Tykk in forum New To JavaReplies: 7Last Post: 10-04-2009, 10:26 PM -
Some while loop problem need help
By shaggyoo7 in forum New To JavaReplies: 4Last Post: 01-14-2009, 07:16 PM -
Loop Problem
By jralexander in forum New To JavaReplies: 4Last Post: 12-02-2008, 07:08 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks