elif

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kid Programmer
    New Member
    • Mar 2008
    • 176

    elif

    Hello guys. I was wondering if you could use a thing in python in java. That is an elif statement. It is saying else if. It will execute a block of code if the condition in the if statement is false and the condition in the elif statement is true. So can you do this?
  • BigDaddyLH
    Recognized Expert Top Contributor
    • Dec 2007
    • 1216

    #2
    Originally posted by Kid Programmer
    Hello guys. I was wondering if you could use a thing in python in java. That is an elif statement. It is saying else if. It will execute a block of code if the condition in the if statement is false and the condition in the elif statement is true. So can you do this?
    That's just a shorthand used in languages like Python because of the way they define blocks and statements. In Java you just write the code:
    [CODE=Java]
    if (condition1) {

    } else if (condition2) {

    } else {

    }[/CODE]
    In VB, for example, this would be:
    [CODE=VB]If Condition1 Then

    ElseIf Condition2 Then

    Else

    End If[/CODE]
    Note: the ElseIf guarantees that only one End If is required.

    Comment

    • Kid Programmer
      New Member
      • Mar 2008
      • 176

      #3
      Originally posted by BigDaddyLH
      That's just a shorthand used in languages like Python because of the way they define blocks and statements. In Java you just write the code:
      [CODE=Java]
      if (condition1) {

      } else if (condition2) {

      } else {

      }[/CODE]
      In VB, for example, this would be:
      [CODE=VB]If Condition1 Then

      ElseIf Condition2 Then

      Else

      End If[/CODE]
      Note: the ElseIf guarantees that only one End If is required.
      Thanks I understand :-)

      Comment

      Working...