Re: scope with if

2017-02-18 Thread Moritz Maxeiner via Digitalmars-d-learn
On Friday, 17 February 2017 at 20:06:19 UTC, berni wrote: I wonder if it's possible to do something like this: import std.stdio; void main(string[] args) { if (args[1]=="a") { write("A"); scope (exit) write("B"); } write("C"); } I expected the output to be ACB not

Re: scope with if

2017-02-18 Thread berni via Digitalmars-d-learn
Just a note - I found something, that works: import std.stdio; void main(string[] args) { immutable cond = args[1]=="a"; if (cond) write("A"); scope (exit) if (cond) write("B"); write("C"); } I'm using the immutable variable to avoid, that the condition changes later.

Re: scope with if

2017-02-17 Thread Profile Anaysis via Digitalmars-d-learn
On Friday, 17 February 2017 at 20:06:19 UTC, berni wrote: I wonder if it's possible to do something like this: import std.stdio; void main(string[] args) { if (args[1]=="a") { write("A"); scope (exit) write("B"); } write("C"); } I expected the output to be ACB not

scope with if

2017-02-17 Thread berni via Digitalmars-d-learn
I wonder if it's possible to do something like this: import std.stdio; void main(string[] args) { if (args[1]=="a") { write("A"); scope (exit) write("B"); } write("C"); } I expected the output to be ACB not ABC. I understand, that the scope ends at the end of the i