Module 6: Control Flow

Complex Sentences — Branching, Looping, and Chaining Logic

You've got the runtime (word order), the type system (measure words), memory management (particles), error handling, a loaded stdlib, and character composition. You can build statements. But your programs are still single-line scripts.

Real programs need control flow — if/else, loops, try/catch, sequential execution. Real Chinese works the same way. Complex sentences use paired connectors that work exactly like the control flow structures you already know. Two keywords, working in tandem, shaping the logic.

// Your Chinese project so far:
import { SVO, TopicComment } from "grammar/runtime";      // Module 1
import { MeasureWords } from "grammar/types";              // Module 2
import { Particles } from "grammar/memory";                // Module 3
import { Negation, Questions } from "grammar/errors";      // Module 4
import * as stdlib from "vocab/core";                      // Module 5

// Now we need logic:
import { If, TryCatch, CauseEffect, And, Loop, EventListener, Chain }
    from "grammar/control-flow";   // THIS MODULE
The pattern: Almost every complex sentence in Chinese uses a paired connector structure. One keyword sets the condition or premise, the other delivers the result or conclusion. Think of them as two-part operators. Once you see the first keyword, you know the second is coming — and you know the shape of the logic.

1. if (condition) { result }如果...就...

The most fundamental control flow structure in any language. A condition, and a branch. In Chinese, 如果 sets up the condition, and fires the result. The comma between them is your opening brace.

// Structure:
如果 [condition],(subject) 就 [result]。

// Maps directly to:
if (condition) {
    result;
}
Chinese Pinyin Code English
如果下雨,我不去了。 Rúguǒ xià yǔ, wǒ jiù bú qù le. if (raining) { cancel(go); } If it rains, I won't go.
如果你累了,休息吧。 Rúguǒ nǐ lèi le, jiù xiūxi ba. if (you.tired) { rest(); } If you're tired, (then) rest.
如果你喜欢,买吧。 Rúguǒ nǐ xǐhuan, jiù mǎi ba. if (you.like(it)) { buy(it); } If you like it, buy it.
如果没问题,我们开始。 Rúguǒ méi wèntí, wǒmen jiù kāishǐ. if (!problems) { start(); } If there's no problem, we'll start.
如果你有时间,来找我。 Rúguǒ nǐ yǒu shíjiān, jiù lái zhǎo wǒ. if (you.hasTime()) { findMe(); } If you have time, come find me.
如果太贵了,我不买了。 Rúguǒ tài guì le, wǒ jiù bù mǎi le. if (price > budget) { skip(); } If it's too expensive, I won't buy it.
Shortcut: In casual speech, you can drop 如果 entirely. The alone is enough to signal the conditional relationship: 累了就休息。 It's like omitting if and just writing condition && action. Shorter. Still works.

2. try { expectation } catch { reality }虽然...但是...

You expect one outcome, but reality throws an exception. 虽然 sets up what you'd expect, and 但是 catches the twist. It's concession logic: "I acknowledge X, however Y."

// Structure:
虽然 [expectation/concession],但是 [actual result]。

// Maps to:
try {
    // You'd expect this to lead somewhere...
    expectation;
} catch (realityCheck) {
    // ...but here's what actually holds.
    actual_result;
}
Chinese Pinyin Code English
虽然很累,但是很开心。 Suīrán hěn lèi, dànshì hěn kāixīn. try { tired } catch { happy } Although (I'm) tired, (I'm) happy.
虽然中文很难,但是很有意思。 Suīrán zhōngwén hěn nán, dànshì hěn yǒu yìsi. try { hard } catch { interesting } Although Chinese is hard, it's interesting.
虽然他很年轻,但是很能干。 Suīrán tā hěn niánqīng, dànshì hěn nénggàn. try { young } catch { capable } Although he's young, he's very capable.
虽然贵,但是质量好。 Suīrán guì, dànshì zhìliàng hǎo. try { expensive } catch { quality++ } Although it's expensive, the quality is good.
虽然我学了,但是还是没通过。 Suīrán wǒ xué le, dànshì háishi méi tōngguò. try { study() } catch { fail() } Although I studied, I still didn't pass.
虽然我不认识他,但是听说过他。 Suīrán wǒ bú rènshi tā, dànshì tīngshuō guo tā. try { !know(him) } catch { heardOf(him) } Although I don't know him, I've heard of him.
Watch this: In English, you say "Although X, Y" — no "but." Or "X, but Y" — no "although." Using both feels redundant. In Chinese, you use both 虽然 AND 但是 together. Always. It's not redundant — it's a matched pair, like opening and closing braces. Drop one and it still compiles, but the full pair is idiomatic.

3. cause: X → result: Y因为...所以...

Pure causal logic. 因为 states the cause, 所以 states the effect. It's structured logging: every outcome has a traceable reason.

// Structure:
因为 [cause],所以 [effect]。

// Like a logger entry:
logger.info({ cause: "raining", effect: "stayed home" });

// Or an assertion:
// GIVEN cause → THEN effect
Chinese Pinyin Code English
因为下雨了,所以我没去。 Yīnwèi xià yǔ le, suǒyǐ wǒ méi qù. { cause: rain, effect: !go } Because it rained, I didn't go.
因为我生病了,所以今天不上班。 Yīnwèi wǒ shēng bìng le, suǒyǐ jīntiān bú shàngbān. { cause: sick, effect: !work } Because I'm sick, I'm not going to work today.
因为他很努力,所以成绩很好。 Yīnwèi tā hěn nǔlì, suǒyǐ chéngjì hěn hǎo. { cause: effort, effect: goodGrades } Because he works hard, his grades are good.
因为太晚了,所以我们打车了。 Yīnwèi tài wǎn le, suǒyǐ wǒmen dǎchē le. { cause: late, effect: taxi() } Because it was too late, we took a taxi.
因为我喜欢编程,所以当了工程师。 Yīnwèi wǒ xǐhuan biānchéng, suǒyǐ dāng le gōngchéngshī. { cause: love(coding), effect: became(engineer) } Because I like programming, I became an engineer.
Same rule as 虽然/但是: English uses "because" OR "therefore" — never both. Chinese uses both 因为 AND 所以. Again: matched pair. You can drop one in casual speech, but using both is the norm. Think of them as the opening and closing tags of a causal block: <because>cause</because><therefore>effect</therefore>.

4. condition1 && condition2不但...而且...

Both conditions are true, and the second one escalates. 不但 establishes the first truth, and 而且 stacks a second one on top. Like the && operator — both sides must be true, and the right side often carries more weight.

// Structure:
不但 [fact A],而且 [fact B (often stronger)]。

// Like &&:
assert(factA && factB);  // both true, B escalates

// Or Array.every():
[factA, factB].every(Boolean);  // all conditions hold
Chinese Pinyin Code English
不但聪明,而且很努力。 Tā búdàn cōngming, érqiě hěn nǔlì. smart && hardworking She's not only smart, but also hardworking.
这家餐厅不但便宜,而且很好吃。 Zhè jiā cāntīng búdàn piányi, érqiě hěn hǎochī. cheap && delicious This restaurant is not only cheap, but also delicious.
不但会说中文,而且会说日语。 Tā búdàn huì shuō zhōngwén, érqiě huì shuō rìyǔ. speaks("zh") && speaks("ja") He not only speaks Chinese, but also Japanese.
这份工作不但有意思,而且工资高。 Zhè fèn gōngzuò búdàn yǒu yìsi, érqiě gōngzī gāo. interesting && highPay This job is not only interesting, but pays well too.
不但来了,而且带了礼物。 Tā búdàn lái le, érqiě dài le lǐwù. showed_up && brought(gifts) He not only came, but also brought gifts.
Escalation matters. The second clause (after 而且) should be equal to or stronger than the first. Like && short-circuit evaluation: if the first condition is already impressive, the second should be even more so. Saying "She's not only a Nobel laureate, but also she likes pizza" is technically grammatical but logically deflating. Keep the escalation climbing.

5. while (more(X)) { more(Y) }越...越...

A recursive, escalating pattern. The more one thing increases, the more something else increases too. It's a feedback loop — like a recursive function whose output amplifies with each call, or a while loop where the condition and the body scale together.

// Structure:
越 [A] 越 [B]
// The more A, the more B.

// Like:
while (true) {
    A++;
    B++;  // B scales with A
}

// Or a reactive pattern:
X.subscribe(value => Y.set(value * scale));
Chinese Pinyin Code English
有趣。 Yuè xué yuè yǒuqù. study++ → interest++ The more you study, the more interesting it gets.
胖。 Yuè chī yuè pàng. eat++ → weight++ The more you eat, the fatter you get.
生气。 Wǒ yuè xiǎng yuè shēngqì. think++ → anger++ The more I think about it, the angrier I get.
天气冷。 Tiānqì yuè lái yuè lěng. time++ → cold++ The weather is getting colder and colder.
她说得快。 Tā shuō de yuè lái yuè kuài. time++ → speed++ She speaks faster and faster.
Special form: 越来越 — "more and more [adjective]." This variant means something is increasing over time, not in response to a specific trigger. 越来越冷 = getting colder and colder. Think of it as a self-incrementing loop: for (;;) { cold++; }. No external driver — the value just keeps climbing on its own.

6. on("event", callback)一...就...

An event listener. The instant something happens, the callback fires. marks the trigger event, and marks the immediate response. Zero delay between event and handler.

// Structure:
(subject) 一 [trigger event],就 [immediate reaction]。

// Maps to:
element.addEventListener("event", () => {
    reaction();  // fires immediately
});

// Or:
emitter.on("trigger", callback);
Chinese Pinyin Code English
到家吃饭。 Wǒ yī dào jiā jiù chīfàn. on("arrive_home", eat) As soon as I get home, I eat.
看到她笑了。 Tā yī kàn dào tā jiù xiào le. on("see_her", smile) As soon as he sees her, he smiles.
躺下睡着了。 Tā yī tǎng xià jiù shuìzháo le. on("lie_down", sleep) She falls asleep as soon as she lies down.
闹钟响,我起床。 Nàozhōng yī xiǎng, wǒ jiù qǐchuáng. alarm.on("ring", getUp) As soon as the alarm rings, I get up.
懂了。 Wǒ yī tīng jiù dǒng le. on("hear", understand) I understood as soon as I heard it.
一...就... vs 如果...就...: Don't confuse these. Both use , but the logic is different. 如果...就 is a conditional: if X might happen, then Y. ...就 is an event listener: when X does happen, Y fires immediately. One is if (maybe), the other is on("definitely").

7. await step1(); await step2();先...然后...

Sequential execution. Do this first, then do that. No branching, no conditions — just ordered steps. It's a Promise chain, an async/await sequence, a pipeline where each stage runs after the previous one completes.

// Structure:
先 [step 1],然后 [step 2]。

// Maps to:
await step1();
await step2();

// Or Promise chain:
step1()
    .then(() => step2());
Chinese Pinyin Code English
吃饭,然后看电影。 Xiān chīfàn, ránhòu kàn diànyǐng. eat().then(watchMovie) First eat, then watch a movie.
学习,然后玩。 Xiān xuéxí, ránhòu wán. study().then(play) First study, then play.
洗澡,然后睡觉。 Xiān xǐzǎo, ránhòu shuìjiào. shower().then(sleep) First take a shower, then sleep.
做完工作,然后去找你。 Wǒ xiān zuò wán gōngzuò, ránhòu qù zhǎo nǐ. finishWork().then(findYou) I'll first finish work, then go find you.
往左,然后往右,然后一直走。 Xiān wǎng zuǒ, ránhòu wǎng yòu, ránhòu yīzhí zǒu. left().then(right).then(straight) First left, then right, then straight ahead.
Chaining more steps: You can chain multiple 然后 connectors for longer sequences, just like chaining .then() calls. You can also swap in (zài) for a slightly different flavor: 先吃饭,再走。 implies "and then after that" — same sequential logic, slightly more casual.

8. Error Severity Levels: 但是 vs 可是 vs 不过

Chinese has multiple words for "but," and they differ in weight — like the difference between throwing a fatal error, logging a warning, or printing a debug message. They all signal contrast, but the severity varies.

// Error severity analogy:
throw new Error("...");     // 但是 — formal, strong contrast
console.warn("...");        // 可是 — informal, moderate contrast
console.log("btw...");      // 不过 — mild, "by the way though"

// All three mean "but." The weight is different.
Word Pinyin Register Severity Use When
但是 dànshì Formal / written throw Error Writing, presentations, making a strong point
可是 kěshì Spoken / casual console.warn Everyday speech, conversation with friends
不过 búguò Soft / gentle console.log Adding a small caveat, softening a contrast

See them in the same sentence frame to feel the difference:

Connector Example Feeling
但是 我想去,但是没有时间。 Firm. Written. Final.
可是 我想去,可是没有时间。 Conversational. Maybe a bit disappointed.
不过 我想去,不过没有时间。 Soft. "I mean, it's fine, just..."
Pairing rules: 虽然 pairs naturally with all three: 虽然...但是... (formal), 虽然...可是... (casual), 虽然...不过... (gentle). In speech, 可是 is the most common by far. Save 但是 for writing and 不过 for when you want to soften the blow.

Control Flow Summary

/**
 * Chinese Control Flow v1.0
 *
 * PAIRED CONNECTORS — your complex sentence toolkit:
 *
 * 1. 如果...就...    if/then         if (cond) { result }
 * 2. 虽然...但是...  although/but    try { X } catch { Y }
 * 3. 因为...所以...  because/so      { cause: X, effect: Y }
 * 4. 不但...而且...  not only/also   A && B
 * 5. 越...越...      the more/more   while(more) { scale++ }
 * 6. 一...就...      as soon as      on("event", callback)
 * 7. 先...然后...    first/then      step1().then(step2)
 *
 * "BUT" VARIANTS — error severity levels:
 * 8. 但是 = throw Error    (formal, strong)
 *    可是 = console.warn   (casual, moderate)
 *    不过 = console.log    (soft, gentle)
 *
 * KEY INSIGHT:
 * - Chinese paired connectors work like MATCHED DELIMITERS
 * - Both halves appear (unlike English which uses one or the other)
 * - First keyword = setup, second keyword = payoff
 * - Drop one in casual speech; keep both in writing
 *
 * NEXT MODULE: Module 7
 * → You've got control flow. Time to build real programs.
 */

You now have the full control flow toolkit. These seven patterns handle the vast majority of complex sentences in everyday Mandarin. The paired-connector system is elegant and predictable — once you hear the first keyword, your brain can already predict the structure of the rest of the sentence. That's not memorization. That's pattern matching. And you're an engineer. Pattern matching is what you do.

Practice what you learned