Showing results for 
Search instead for 
Did you mean: 

Allow trailing semicolons on last item in a code block

Currently in block of code (such as in an OnSelect property), while semicolons (in at least US English) are used to separate functions/actions, the LAST one cannot have a semicolon without PowerApps complaining (often confusingly).   

From a coding perspective, this is very annoying and wastes a lot of the time, especially when one may add or remove functions from a code block, especially when nested in If() and other statements.  For example in the below:




Set( VarA, 123 );
Set( VarB, 456 );
ClearCollect( MyCollection, 
     {     A: 1, B: 2, C: 3    },
     {     A: 4, B: 5, C: 6   }
Set( VarC, 789 )


The last statement must NOT have a semicolon at the end.  However, if I remove this, then I'll also need to remove the semicolon after the end of the ClearCollect().  


But then if I again add another statement at the end again - I'll not only have to readd the semicolon to the end of the ClearCollect(), but will also have to make sure not to have one at the end of the last statement.


While this makes sense from a "list" perspective (where you only use a comma for instance between items), from a coding perspective this is annoying, wastes time, and goes against what most other languages allow.  In some languages everything must end in a semicolon whether last one or not.  But virtually all at least ALLOW the final statement to have a semicolon (Yes, I can think of a few other exceptions).  


This just simply wastes time of the user.  Please change the parser to allow an OPTIONAL semicolon at the end of statements at the end of a code block (including code blocks within other calls, like If(), etc).


Status: Completed
Regular Visitor

Definitely agree with you, that would help in making the formula system feel better and less aggravating to troubleshoot.


Even just an error message that directly indicates that the trailing semicolon is the problem would make a big difference. As is now, it just states that an operand is expected, but that's not even very clear as that doesn't state that a function is missing but simply a value (eg. 1, "Hello", True); that doesn't do a good job of indicating that the problem lies with the trailing semicolon as opposed to within a function.

Not applicable

I've wasted a LOT of time due to lack of ability for a trailing semicolon.


Biggest issue is when you comment out large lines of code for testing purposes.  (I do thank Microsoft for FINALLY adding proper commenting ability).  This has made a BIG difference positively (just the ability to disable code is HUGE).  


So back to the semicolon - not allowing for a trailing semicolon can really be a pain when commenting out large lines of code.  You need to remember to remove the semi in some cases, adn then later add it back in.


And since PowerApps doesn't always do a great job highlighting the errors (often it marks in red all over the place on a minor error) - I've spent a couple of hours lately all due to a semicolon issue...  (now that I know this, its the first thing I check now).  



Advocate I

This is an easy parser change to make developing apps much easier while reducing frustration. Great thought.

Not applicable

FYI - in the meantime, here is a short workaround that i use during development:


So at the bottom of each page with code (especially those with more than one line):


If(false, Set( gDummy, 0 ) )

So by doing this as the last statement in the code block (which would not have a ";" at the end), I don't have to worry about things in between.  


And the code above shouldn't really do anything (hence the If(false)) including the setting of the variable.  I'm basically just trying to do a "NOOP" here, perhaps there is something shorter to do so.  🙂    


That said - this doesn't resolve the annoyances of inner code blocks (nested inside other function calls) - only for the whole page.


But it has 

Power Apps
Status changed to: Under Review

Updating status and adding @GregLi and @LanceDelano

Frequent Visitor

Instead of using a If statement you could just add false at the end a few lines down. 

//Code........; false
Not applicable

@Borton - Excellent point...  I may do this instead for the time being.

Power Apps
Status changed to: Completed
Not applicable

Great to see this one delivered!

Advocate V

I'm not sure of this, but maybe @GregLi can weigh in.....


I believe that you will still get the "Expected an operand. blah blah blah" error for formulas that end with a semicolon (aka trailing semi-colon) if the formula is NOT a behavior formula (e.g. OnSelect, OnChange, OnVisible).


For example, if you use the following in the non-behavioral Width property/formula, you'll get red squiggly and an "Expected an operand." error.


Assuming my assessment about behavioral v. non-behavioral is correct, I guess this makes sense in that there should never be multiple (stand-alone) statements in a non-behavioral formula.  So the editor's error-checker must just flag ANY semi-colon in these properties.  But, it sure would be nice if it would just allow them across the board.