Obsecure problem 1
Salih Dincer
salihdb at hotmail.com
Sun Jul 31 17:03:59 UTC 2022
On Sunday, 31 July 2022 at 15:01:21 UTC, pascal111 wrote:
>
> I don't know how "assert" works, if you explained it I'll be
> able to get the idea of your suggestion to apply the
> appropriate changes on my code.
**// This code runs forever:**
```d
string str;
assert(str is null);
str = "test";
assert(str !is null);
assert(str.length >= 1);
str = "";
assert(str !is null);
assert(str.length == 0);
int count;
assert(count == 0); // true
assert(true);
while(true) { // endless loop }
```
**// This code runs in a little bit:**
```d
count = 100;
//assert(count); /* or:
assert(count > 1); //*/
while(--count) { }
assert(count); // false and assert error
```
>> But if it's because of typos, it's ok. Lets continue...
>>
> I think "typos" are mistakes of typing? I'm not sure.
Yes, typos == "mistakes of typing" for example:
```d
void main()
{
import std.string : split;
auto test = "I hav e a car s";
auto result = split!string(test, " ");
// ["I", "hav", "e", "a", "car", "", "s"]
auto tilly = result[2]; // extra character
auto solecism = result[3]; // car is plural
auto doubled = result[5]; // doubled separetor
import std.stdio : writeln;
writeln(tilly, solecism, doubled);
}
```
SDB at 79
More information about the Digitalmars-d-learn
mailing list