Switch statement with nested If statement 
Author Message
 Switch statement with nested If statement

I have an error that occurs when I include a nested If test within a
Switch statement. The error I receive is:

extra characters after close-brace
    while compiling
"if {$UpgradeCount2 > 3"
    ("completeFromMgt" arm line 3)
    invoked from within
"switch -exact [lindex [lindex $result 1] 1] {
                   No                                   { putf "Software upgrade - offline; delaying 5
seconds"; after 5000}
                   inProgress    ..."
    (procedure "WAITUPGRADE2" line 31)

The matches in question are the completeFromMgt and
completeFromProvisioning. I had put the <CR> at each line wrap for
this post readability since I tried putting all the statements on one
line. You can take them out (<CR>) and the error still occurs. I also
tried putting a statement on each line within the swtich matched
statement which also created the same error. Any help in this error
would be greatly appreciated.

Thanks JChristensen

The code snippet is as follows:

       if { [lindex $result 0] == 0 } {
         switch -exact [lindex [lindex $result 1] 1] {
                   No                       { putf "Software upgrade - offline;
delaying 5 seconds"; after 5000}
                   inProgress               { putf "Software upgrade - inProgress;
delaying 5 seconds"; after 5000}
                   completeFromProvisioning { putf "Software upgrade completed -
completeFromProvisioning"
                                              incr UpgradeCount;
                                              if {UpgradeCount > 3 }{
                                              putf "Software upgrade
completed - completeFromProvisioning";
                                              set UpgradeCount 0;
return 0 } }
                   completeFromMgt          { putf "Software upgrade completed -
completeFromMgt";
                                              incr UpgradeCount2;
                                              if {UpgradeCount2 > 3 }{
                                              putf "Software upgrade
completed - completeFromProvisioning";
                                              set UpgradeCount 0;
                                              return 0 } }
                   failed               { putf "Software upgrade failed"; return 0 }
                   other                { putf "Software upgrade reported Other"; return 0 }
                   default              { putf "Waiting for software upgrade... -- $result";
after 5000}
         }
       }
     }



Mon, 18 Apr 2005 06:29:31 GMT  
 Switch statement with nested If statement

Quote:

> I have an error that occurs when I include a nested If test within a
> Switch statement. The error I receive is:

> extra characters after close-brace
>     while compiling
> "if {$UpgradeCount2 > 3"
>     ("completeFromMgt" arm line 3)
>     invoked from within
> "switch -exact [lindex [lindex $result 1] 1] {
> No                                    { putf "Software upgrade - offline; delaying 5
> seconds"; after 5000}
> inProgress    ..."
>     (procedure "WAITUPGRADE2" line 31)

I think you need a space after  if {$UpgradeCount2 > 3}

so,
  if {$UpgradeCount2 > 3}{
should be
  if {$UpgradeCount2 > 3} {

At least that's what it appears from this posting...



Mon, 18 Apr 2005 06:45:26 GMT  
 Switch statement with nested If statement

Quote:
> I have an error that occurs when I include a nested If test within a
> Switch statement. The error I receive is:

> extra characters after close-brace
>     while compiling
> "if {$UpgradeCount2 > 3"
>     ("completeFromMgt" arm line 3)
>     invoked from within
> "switch -exact [lindex [lindex $result 1] 1] {
>    No     { putf "Software upgrade - offline; delaying 5
> seconds"; after 5000}
>    inProgress    ..."
>     (procedure "WAITUPGRADE2" line 31)

Untangle it and you will find one too many braces. Try this:

if { [lindex $result 0] == 0 } {
   switch -exact [lindex [lindex $result 1] 1] {
      No                     {
         putf "Software upgrade - offline;delaying 5 seconds"; after 5000
      }
      inProgress               {
         putf "Software upgrade - inProgress; delaying 5 seconds"; after
5000
      }
      completeFromProvisioning {
         putf "Software upgrade completed - completeFromProvisioning"
         incr UpgradeCount;
         if {$UpgradeCount > 3 } {
            putf "Software upgrade completed - completeFromProvisioning";
            set UpgradeCount 0;
            return 0
         }
      }
      completeFromMgt     {
         putf "Software upgrade completed - completeFromMgt";
         incr UpgradeCount2;
         if {$UpgradeCount2 > 3 } {
            putf "Software upgrade  completed - completeFromProvisioning";
            set UpgradeCount 0;
            return 0
         }
      }
      failed {
         putf "Software upgrade failed"; return 0
      }
      other {
         putf "Software upgrade reported Other";
         return 0
      }
      default {
         putf "Waiting for software upgrade... -- $result";
         after 5000
      }
   }

Quote:
}

Tom Wilkason


Mon, 18 Apr 2005 06:39:23 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. That nested nested nested if statement...

2. Nested inspect statements

3. nested case statement latch inference problem

4. Nested IF-THEN-ELSIF statements

5. Nested Generate statements

6. Nested CASE statements?

7. HELP! nested CASE statement

8. Nested PERFORM statements

9. HELP! nested CASE statement

10. Avoiding nested IF conditionals,and STOP statement

11. nested bind statements -allowed?

12. case statement flipflop statement

 

 
Powered by phpBB® Forum Software