Repeating different parts of a program
currently i'm working on a java assignment in class. the instructor is asking us to repeat a different part of the program.
for example, through an if statement, if the input from the user meets the condition of the if statement then the loops statement before it would be repeated.
i dont know how im suppose to write that because i am new to java.
any help would be appreciated.
Re: Repeating different parts of a program
Quote:
Originally Posted by
swiftxjames
currently i'm working on a java assignment in class. the instructor is asking us to repeat a different part of the program.
for example, through an if statement, if the input from the user meets the condition of the if statement then the loops statement before it would be repeated.
i dont know how im suppose to write that because i am new to java.
any help would be appreciated.
Typically, any code that may be required to be executed from different points in the program flow is factored out to a separate method.
db
Re: Repeating different parts of a program
Quote:
Originally Posted by
Darryl.Burke
Typically, any code that may be required to be executed from different points in the program flow is factored out to a separate method.
db
so ur saying that i have to just rewirte the method or copy and paste it into that if statement?
Re: Repeating different parts of a program
Quote:
Originally Posted by
swiftxjames
currently i'm working on a java assignment in class. the instructor is asking us to repeat a different part of the program.
for example, through an if statement, if the input from the user meets the condition of the if statement then the loops statement before it would be repeated.
i dont know how im suppose to write that because i am new to java.
any help would be appreciated.
You can usually repeat a part of a program by
while(condition)
{
code
}
or
for (int x = whatever; x < something; x++)
{
code
}
or something like that.