Expected expression after operation

I feel as if I typed in the code verbatim from the book and I keep getting this error. Can anyone identify why?


There is a syntax error on line 27.

var currentQuestionIndex : Int = 0

The ellipsis, three dots, after the var declaration is upsetting the compiler.

After the var declaration, the compiler is trying to parse the following phrase (a range expression):


But the UpperBound is missing, causing the error message you are getting.

To my surprise, although syntactically mis-formed, the following code still compiles without any errors!

var foo : Int = 5


func fooBar() {
1 Like

Thanks. I guess I was typing in the code a little to literal.

It compiles because it’s actually valid syntax. The trick is that ...7 creates a PartialRangeThrough<Int> instance with upperBound of 7. That winds up being an unused result – you made this thing, and then lost your only reference to it, so you can’t even do anything with it! – but it’s not malformed.

You should be able to see this by assigning the result to a variable and getting info on it to gets its type, or by running the ...7 line in the Swift REPL.

@jdstik: Looks like you ran afoul of a notational convention. Sorry about that. :frowning:

The book often uses an ellipsis (the three dots) to say “this part hasn’t changed, nothing interesting to see here”. It means you should leave whatever code originally followed the part you were directed to change – the part represented by the ellipsis – alone.

Hi bro, aren’t you over the strings? That should make it much more simplier.

H.Smith https://plex.software/ https://tutuappx.com/