This site requires JavaScript, please enable it in your browser!
Greenfoot back
abcmike
abcmike wrote ...

2011/12/5

'Then' statement

abcmike abcmike

2011/12/5

#
I was wondering what the equivalent of a 'then' statement is in Greenfoot. I have an if statement but with more than one output e.g. if this is true do this, then this and finally this. What would be a suitable way of writing this in code?
mjrb4 mjrb4

2011/12/5

#
Do you mean else?
if(condition) {
    //do this if true
}
else {
    //do this if false
}
If you just want to do one thing after another in an if statement then just put the corresponding code in the block like so:
if(condition) {
    System.out.println("hello");
    System.out.println("I'm here");
    System.out.println("Goodbye");
}
You need to login to post a reply.