Thursday, May 27, 2010

Elif command

The elif command allows you to put several else-like commands in a row. It works like a combination of else and if.

for example:

if < insert condition here >:
< insert action here >

elif
< insert condition here >:
< insert action here >

elif
< insert condition here >:
< insert action here >
etc. etc.

This makes it so that the elif only executes if the first if is false, and will execute in order, so be careful of that.

Note: ALWAYS remember to indent the line after the else, elif and if commands and put the colon after the condition.

This becomes extremely helpful if there are several different outcomes for a single action.

Next Post: Random Numbers

No comments:

Post a Comment